<?php
namespace app\admin\controller;


/**
 * @title 系统配置
 * @description 接口说明
 * @group admin
 * @header name:authorization require:1 default: desc:登陆的token
 */
class Config extends Base
{
    protected $_order = 'sort asc, id asc';

    /**
     * @title 获取
     * @description 接口说明
     * @author hardy
     * @url /admin/Config
     * @method GET
     *
     * @param name:type type:int require: default:key-value other: desc:默认情况返回键值对，非默认情况返回所有配置信息
     *
     * @return company_logo:公司LOGO
     * @return company_number:公司公众号
     * @return union_logo:联盟LOGO
     * @return union_number:联盟公众号
     * @return org_name:机构名称
     * @return org_phone:官方电话
     * @return fax:传真
     * @return email:邮箱
     * @return postal_code:邮编
     * @return place_position:定位
     * @return ICP_number:ICP备案编号
     * @return ICP_link:ICP备案链接
     * @return company_desc:公司简介
     * @return setting_email:招聘设置-邮件申请
     * @return setting_tel:招聘设置-电话申请
     *
     */
    public function gets()
    {
        $type = input('type', 'key-value');
        $model = $this->controller;
        $data_list = model($model)->getConfigList($type);
        $this->responseSuccess($data_list);
    }
    /**
     * @title 创建
     * @description 接口说明
     * @author hardy
     * @url /admin/Config
     * @method POST
     *
     *
     * @param name:name type:string require:1 default: other: desc:配置名称
     * @param name:value type:string require:1 default: other: desc:配置值
     * @param name:title type:string require: default: other: desc:中文名
     * @param name:remark type:string require: default: other: desc:配置说明，注解
     * @param name:type type:string require: default: other: desc:配置类型
     * @param name:sort type:string require: default: other: desc:排序
     *
     * @return name:配置名称
     * @return value:配置值
     */
    public function create(){
        parent::create();
    }
    /**
     * @title 修改
     * @description 接口说明
     * @author hardy
     * @url /admin/Config
     * @method put
     *
     * @param name:company_logo type:string require:1 default: other: desc:公司LOGO
     * @param name:company_number type:string require:1 default: other: desc:公司公众号
     * @param name:union_logo type:string require:1 default: other: desc:联盟LOGO
     * @param name:union_number type:string require:1 default: other: desc:联盟公众号
     * @param name:org_name type:string require:1 default: other: desc:机构名称
     * @param name:org_phone type:string require:1 default: other: desc:官方电话
     * @param name:fax type:string require:1 default: other: desc:传真
     * @param name:email type:string require:1 default: other: desc:邮箱
     * @param name:postal_code type:string require:1 default: other: desc:邮编
     * @param name:place_position type:json require:1 default: other: desc:定位
     * @param name:ICP_number type:string require:1 default: other: desc:ICP备案编号
     * @param name:ICP_link type:string require:1 default: other: desc:ICP备案链接
     * @param name:company_desc type:string require:1 default: other: desc:公司简介
     * @param name:setting_email type:string require:1 default: other: desc:招聘设置-邮件申请
     * @param name:setting_tel type:string require:1 default: other: desc:招聘设置-电话申请
     *
     * @return company_logo:公司LOGO
     * @return company_number:公司公众号
     * @return union_logo:联盟LOGO
     * @return union_number:联盟公众号
     * @return org_name:机构名称
     * @return org_phone:官方电话
     * @return fax:传真
     * @return email:邮箱
     * @return postal_code:邮编
     * @return place_position:定位
     * @return ICP_number:ICP备案编号
     * @return ICP_link:ICP备案链接
     * @return company_desc:公司简介
     * @return setting_email:招聘设置-邮件申请
     * @return setting_tel:招聘设置-电话申请
     */
    public function update(){
        $data = input('put.');
        $model = $this->controller;
        $model = model($model);
        foreach ($data as $key=>$v){
            $one = model('Config')->where('name', $key)->find();
            $where = [
                'name' => $key,
            ];
            if ($one['type'] == 'json'){
                $value = [
                    'value' => serializeByArray($v)
                ];
            } else{
                $value = [
                    'value' => $v
                ];
            }
            if($model->update($value, $where) == false){
                $this->responseFail($model->getError());
            }
        }
        $data_list = $model->getConfigList();
        $this->responseSuccess($data_list);
    }
}